$("#Switchbox", window.parent.parent.document).on("click", function () {
    ModeSwitch.modeSwitch();
    commonbgcolor();
    markbgcolor();
})

//自适应高度(iframe加载完毕后调用)
function noteiframeOn() {
    var iframeObj = document.getElementById('darkMode');

    $('#markdown', window.parent.document).css('height', iframeObj.scrollHeight);

    window.parent.iframeOn('notes');
}

//返回
function closenote() {
    window.parent.closenote();
    window.parent.iframeOn('notes');
}

function opennote(url) {
    var note = `
        <button id="back" onclick="closenote()" type="button">
            <i class="fa fa-arrow-to-left">返回</i>
        </button>
        `
    $.ajax({
        sync: false,
        type: 'GET',
        dataType: 'json',
        url: 'https://gitee.com/api/v5/repos/' + giteeID + '/mweb/contents/' + url,
        success: function (result) {
            var data = utf8to16(window.atob(result.content));

            document.getElementById('darkMode').innerHTML = note + data.match(/<[\s]*section[\s]+class[\s]*=[\s]*"ct-body"[\s]*>.*<[\s]*[\/][\s]*section[\s]*>/gs)[0].replaceAll('media', 'https://gitee.com/' + giteeID + '/mweb/raw/master/media').replaceAll('<img src=', '<img onload="noteiframeOn()" src=');
            setTimeout(() => {
                noteiframeOn();
                $('#markdown', window.parent.document).css('height', $('.ct-body').Height)
            })
        }
    })
}